home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / tpstuff2.arc / FILTER.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1984-12-01  |  1.4 KB  |  59 lines

  1. Program Filter;
  2.  
  3. { This is an example of a simple MS-DOS filter written in Turbo Pascal.
  4.   This filter copies its standard input to its standard output with all
  5.   letters converted to lowercase.
  6.  
  7.   The MS-DOS facilities of redirection, piping, and simultaneous printing
  8.   through the use of ^P or ^PrtSc will work on any program that has the 2
  9.   procedure/functions used, and has the statements   ConInPtr:=Ofs(GetC);
  10.   ConOutPtr:=Ofs(PutC);  in it.
  11.  
  12.   Input is read from Kbd to prevent echoing.
  13.  
  14.   Try FILTER <file.ext >newfile.ext.  The file file.ext should be copied
  15.   to newfile.ext with all letters converted to lowercase.
  16.  }
  17.  
  18.   Type
  19.     RegisterSet=Record Case Integer Of
  20.                   1: (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: Integer);
  21.                   2: (AL,AH,BL,BH,CL,CH,DL,DH: Byte);
  22.                 End;
  23.  
  24.   Var
  25.     Regs: RegisterSet;
  26.  
  27.  
  28.   Function GetC: Byte;
  29.  
  30.     Begin
  31.       Regs.AH:=8;
  32.       MsDos(Regs);
  33.       GetC:=Regs.AL;
  34.     End;
  35.  
  36.   Procedure PutC(C: Byte);
  37.  
  38.     Begin
  39.       Regs.AH:=2;
  40.       Regs.DL:=C;
  41.       MsDos(Regs);
  42.     End;
  43.  
  44.   Var
  45.     S: String[255];
  46.     I: Byte;
  47.  
  48.   Begin
  49.     ConInPtr:=Ofs(GetC);
  50.     ConOutPtr:=Ofs(PutC);
  51.     While Not Eof(Kbd) Do
  52.      Begin
  53.       ReadLn(Kbd,S);
  54.       For I:=1 To Length(S) Do
  55.         If (S[I]>='A') And (S[I]<='Z') Then S[I]:=Chr(Ord(S[I])+32);
  56.       WriteLn(S);
  57.      End;
  58.   End.
  59.